<template>
  <div>
    <div class="list-container">
      <el-table
        :data="list"
        :cell-style="cellStyle"
        :row-class-name="tableRowClassName"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column label="供货商结账单号" min-width="140">
          <div slot-scope="scope">
            <span>{{ scope.row['供货商结账单号'] }}</span>
          </div>
        </el-table-column>
        <el-table-column label="供货商简称" align="center" min-width="100">
          <div slot-scope="scope" class="font12">
            <span>{{ scope.row['供货商简称'] }}</span>
          </div>
        </el-table-column>
        <el-table-column label="结账单生成时间" align="center" min-width="160">
          <div slot-scope="scope" class="font12">
            <span>{{ scope.row['时间'] }}</span>
          </div>
        </el-table-column>
        <el-table-column label="发票号" align="center" min-width="160">
          <div slot-scope="scope" class="font12">
            <span>{{ scope.row['发票号'] }}</span>
          </div>
        </el-table-column>
        <el-table-column label="总价" min-width="100" align="center">
          <div slot-scope="scope" class="font12">{{ scope.row['总价'] }}</div>
        </el-table-column>
        <el-table-column label="操作" min-width="150" align="center">
          <template slot-scope="scope">
            <!-- <el-button type="text" @click="tableDatatwo(scope.row)">详情</el-button> -->
            <el-button type="text" @click="printInvoice(scope.row)">打印发票</el-button>
            <el-button type="text" @click="printJZ(scope.row)">合同打印</el-button>
            <el-button type="text" @click="print(scope.row)">配送单打印</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import { fetchList } from '@/api/api'
import config from '#/api.config'

export default {
  name: 'Uncheck', data() {
    return {
      list: [],
      multipleSelection: [],
      date: this.getNowFormatDate()
    }
  },
  created() {
    this.getList()
  },
  methods: {
    printInvoice(row) {
      if (row['发票号'] === '') {
        this.$message.error('请选择发票')
        return
      }
      const param = {
        query: 'vue_供货商发票打印',
        发票号: row.发票号,
        老师结账单号: row.供货商结账单号,
        username: localStorage.getItem('ghusername')
      }
      fetchList(param).then(({ data }) => {
        if (data.message === 'file') {
          window.location.href = config.baseUrl + data.data
        }
      })
    },
    print(row) {
      const param = { query: 'vue_供货商结账配送单打印', username: localStorage.ghusername, 结账单号: row.供货商结账单号 }
      fetchList(param).then(({ data }) => {
        if (data.message === 'file') {
          window.location.href = config.baseUrl + data.data
        }
      })
    },
    tableDatatwo(item) {
      this.$router.push({
        name: '供货商结账单明细',
        query: { id: item['供货商结账单号'] }
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    printJZ(row) {
      const param = {
        query: 'vue_合同打印',
        老师结账单号: row.供货商结账单号,
        供货商编号: row.供货商编号
      }
      fetchList(param).then(({ data }) => {
        if (data.message === 'file') {
          window.location.href = config.baseUrl + data.data
        }
      })
    },
    getList() {
      const param = { query: 'vue_供货商历史结账单', 供货商编号: localStorage.ghusername }
      fetchList(param).then(({ data }) => {
        console.log(data)
        if (data.flag === '0') {
          this.list = []
          return
        }
        this.list = data.data
      })
    },
    cellStyle({ row, column, rowIndex, columnIndex }) {
      return 'border:0px'
    },
    getNowFormatDate() {
      var date = new Date()
      var seperator1 = '-'
      var year = date.getFullYear()
      var month = date.getMonth() + 1
      var strDate = date.getDate()
      if (month >= 1 && month <= 9) {
        month = '0' + month
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = '0' + strDate
      }
      var currentdate = year + seperator1 + month + seperator1 + strDate
      return currentdate
    },
    tableRowClassName({ row, rowIndex }) {
      if (this.list[rowIndex]['发票号'] !== '未填写') {
        return 'success-row'
      } else {
        return 'warning-row'
      }
    }
  }
}
</script>

<style scoped>
.toolbar {
  margin-top: 5px;
  height: 40px;
  display: flex;
  flex-direction: row;
  align-items: center;
}
.list-container {
  max-height: 80vh;
  overflow: scroll;
  margin-top: 5px;
}
</style>

